<?php

class query_db extends CI_Model
{
    function CATEGORY_SELECT_ALL()
    {
        $this->db->db_debug = FALSE;
        $query=$this->db->query('SELECT CAT.*,(SELECT COUNT(SUB_CATEGORY_ID) FROM `SUB_CATETGORY` WHERE SUB_CATEGORY_ID=CAT.CATEGORY_ID) AS COUNT_SUB_CAT FROM `CATETGORY` AS CAT ORDER BY CAT.ORDER_NO');
        return $query->result_array();
    }
    function CATEGORY_SELECT_ID($ID)
    {
        $this->db->db_debug = FALSE;
        $query=$this->db->query('SELECT * FROM `CATETGORY` WHERE ID=? ORDER BY ORDER_NO',array($ID));
        return $query->result_array();
    }
    function SUB_CATEGORY_SELECT_ALL()
    {
        $this->db->db_debug = FALSE;
        $query=$this->db->query('SELECT * FROM `SUB_CATETGORY` ORDER BY ORDER_NO');
        return $query->result_array();
    } 
    function SUB_CATEGORY_SELECT_CATEGORY_ID($ID)
    {
        $this->db->db_debug = FALSE;
        $query=$this->db->query('SELECT * FROM `SUB_CATETGORY` WHERE SUB_CATEGORY_ID=? ORDER BY ORDER_NO',array($ID));
        return $query->result_array();
    }    
    function getKeyWord($like)
    {
        $this->db->db_debug = FALSE;
        $query=$this->db->query("SELECT WORD FROM `KEYWORD` WHERE WORD LIKE '$like%' ORDER BY WORD");
        return $query->result_array();
    }  
}
?>